package Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Entities.LoginEntity;
import GUI.MakeOfferGUI;
import GUI.SalesManGUI;

/**
 * The Class SalesManController.
 * Controller for sales man activities.
 */
public class SalesManController {
	
	/** The sm gui. */
	private SalesManGUI smGUI;
	
	/** The login entity. */
	private LoginEntity loginEnt;
	
	/**
	 * Instantiates a new sales man controller.
	 *
	 * @param smGUI the sm gui
	 * @param loginEnt the login entity
	 */
	public SalesManController(SalesManGUI smGUI,LoginEntity loginEnt) {
		
		this.smGUI = smGUI;
		this.loginEnt=loginEnt;
		this.smGUI.addMakeOfferListener(new MakeOfferListener());
		this.smGUI.setVisible(true);
	}

	/**
	 * Gets the sm gui.
	 *
	 * @return the sm gui
	 */
	public SalesManGUI getSmGUI() {
		return smGUI;
	}

	/**
	 * Sets the sm gui.
	 *
	 * @param smGUI the new sm gui
	 */
	public void setSmGUI(SalesManGUI smGUI) {
		this.smGUI = smGUI;
	}
	
	/**
	 * The listener interface for receiving makeOffer events.
	 * The class that is interested in processing a makeOffer
	 * event implements this interface, and the object created
	 * with that class is registered with a component using the
	 * component's <code>addMakeOfferListener<code> method. When
	 * the makeOffer event occurs, that object's appropriate
	 * method is invoked.
	 *
	 * @see MakeOfferEvent
	 */
	class MakeOfferListener implements ActionListener
	{

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent arg0) {
			
			MakeOfferGUI moGUI=new MakeOfferGUI();
			new MakeOfferController(moGUI,loginEnt).setPrev(SalesManController.this);
			LoginController.mainWindow.setContentPane(moGUI);
			LoginController.mainWindow.setTitle("Make Offer");
		}
		
	}
}
